import { defineStore } from "pinia";
// 引入请求接口
import { reqC1List, reqC2List, reqC3List } from "@/api/product/attr/attr";
// 引入数据类型
import type { categoryStoreStateType } from "./interface/category"; 
const useCategoryStore = defineStore("category", {
  state: ():categoryStoreStateType => ({
    // 一级分类数据存储
    c1List: [],
    // 一级分类id
    c1id: "",
    // 二级分类数据存储
    c2List: [],
    // 二级分类id
    c2id: "",
    // 三级分类数据存储
    c3List: [],
    // 三级分类id
    c3id: "",
  }),

  actions: {
    async getC1List() {
      // 获取一级分类数据
      let result = await reqC1List();
      this.c1List = result;
    },
    // 一级下拉菜单触发change事件,获取二级分类数据
    async getC2List() {
        // console.log(this.c1id,111111111111111);
    // 清空下两级数据及id
    this.c2List=[];
    this.c2id=''
    this.c3List=[];
    this.c3id=''
    
      // 获取二级分类数据
      let result = await reqC2List(this.c1id);
      this.c2List = result;
    },
       // 二级下拉菜单触发change事件,获取三级分类数据
       async getC3List() {
        // 清空三级分类数据及id
        this.c3List=[];
        this.c3id=''
        // 获取三级分类数据
        let result = await reqC3List(this.c2id);
        this.c3List = result;
      },
  },
});
//对外暴露
export default useCategoryStore;